﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class PlayerTargetConfig extends Object
    {
        private var _dic:Dictionary;
        private var _targetDic:Dictionary;
        private static var _instance:PlayerTargetConfig;

        public function PlayerTargetConfig()
        {
            this._dic = new Dictionary();
            this._targetDic = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" PlayerTargetConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_equip_target.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TEquipTarget = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TEquipTarget();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (this._dic[_loc_2.type] == null)
                {
                    this._dic[_loc_2.type] = new Array();
                }
                (this._dic[_loc_2.type] as Array).push(_loc_2);
                this._targetDic[_loc_2.id] = _loc_2;
            }
            return;
        }// end function

        public function getTargetByTypeAndLevel(param1:String, param2:int) : TEquipTarget
        {
            return (this._dic[param1] as Array)[param2];
        }// end function

        public function getTargetListByType(param1:String) : Array
        {
            return this._dic[param1] as Array;
        }// end function

        public function getTargetByTypeAndId(param1:String, param2:int) : TEquipTarget
        {
            var _loc_4:TEquipTarget = null;
            var _loc_3:* = this._dic[param1] as Array;
            for each (_loc_4 in _loc_3)
            {
                
                if (_loc_4.id == param2)
                {
                    return _loc_4;
                }
            }
            return null;
        }// end function

        public function getInfoById(param1:int) : TEquipTarget
        {
            return this._targetDic[param1];
        }// end function

        public static function get instance() : PlayerTargetConfig
        {
            if (_instance == null)
            {
                _instance = new PlayerTargetConfig;
            }
            return _instance;
        }// end function

    }
}
